const fs = require('fs')
function getMockData() {

    console.time('mock')
    const number = 6000;
    const nodes = [];
    const edges = [];

    const categories = [
        {
            name: "组织A",
            symbol: "circle",
            color: '#5470c6'
        },
        {
            name: "组织B",
            symbol: "circle",
            color: '#91cc75'
        },
        {
            name: "组织C",
            symbol: "circle",
            color: '#fac858'

        },
        {
            name: "组织D",
            symbol: "circle",
            color: '#ee6666'
        },
        {
            name: "组织E",
            symbol: "circle",
            color: '#73c0de'
        },
        {
            name: "组织F",
            symbol: "circle",
            color: '#3ba272'
        },
        {
            name: "组织G",
            symbol: "circle",
            color: '#fc8452'
        },
        {
            name: "组织H",
            symbol: "circle",
            color: '#9a60b4'
        },
        {
            name: "组织I",
            symbol: "circle",
            color: '#ea7ccc'
        }
    ]

    for (let i = 0; i < number; i++) {
        const category = i % 9; //分类
        const size = Math.random() * 30 + 5;
        const color = categories[category].color;
        const id = `id_${i}`;
        nodes.push({
            category,
            id,
            size,
            label: `李${i}`,
            style: {
                fill: color,//节点填充色
                stroke: color,//节点的描边颜色
            },
            stateStyles: {
                highlight: {
                    fill: color,//节点填充色
                    stroke: color,//边缘颜色
                },
                dark: {
                    fill: color,//节点填充色
                    stroke: color,//边缘颜色
                },
            }
        })
    }

    for (let i = 0; i < number; i++) {
        let target = nodes[i].id;
        let color = nodes[i].style.fill;
        let num = 1 + parseInt((Math.random() * 1).toFixed()) //1~2
        for (let j = 0; j < num; j++) {
            let randomIndex = parseInt((Math.random() * (number - 1)).toFixed());//0~number-1
            let source = nodes[randomIndex].id;
            // let existed = edges.find(item => (item.source === source && item.target === target) || (item.source === target && item.target === source))
            if (source !== target) {

                edges.push({
                    id: `edges-${i}-${j}`,
                    source,//起始点 id
                    target,//结束点 id
                    // label: `${source}->${target}`,
                    style: {
                        stroke: color,
                    },
                    stateStyles: {
                        highlight: {
                            stroke: color,
                        },
                        dark: {
                            stroke: color,
                        },
                    }
                })
            }
        }
    }
    let data = {
        nodes,
        edges,
        categories
    }
    fs.writeFileSync(`data-${number}.json`, JSON.stringify(data));

    console.timeEnd('mock')

}
getMockData();
